package org.pc2r.game.model;

public class Position implements Comparable<Position> {

	private int x;
	private int y;
	private boolean isTouched;

	public Position(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}

  public boolean isNext(Position p) {
    if(p.getX() != (x + 1)) {
      return p.getY() == (y + 1);
    }
    return true;
  }
  
  public boolean isHorizontal(Position p) {
    return y == p.y;
  }
	
	public int getX() {
		return x;
	}
	
	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public boolean isTouched() {
		return isTouched;
	}

	public void setTouched(boolean isTouched) {
		this.isTouched = isTouched;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Position other = (Position) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

	@Override
	public int compareTo(Position o) {
		int x1 = (x - o.x);
		if (x1 != 0) return x1;
		
		return (y - o.y);
	}
	
	public String toString() {
	  return x + " - " + (char) ( y + 65);
	}
}
